package org.springmvc.web.servlet.mvc.method;

import java.util.Objects;

/**
 * @author marin
 * @version 1.0
 * @date 2025/9/2 23:13
 * @desc 是 Spring 用来 保存和描述请求映射信息 的对象。
 *  *       1.Spring MVC 的 RequestMappingHandlerMapping 会用 RequestMappingInfo 来保存 @RequestMapping 和实际控制器方法的映射关系。
 *  *       2.每次收到 HTTP 请求时，DispatcherServlet 会根据请求 URL、请求方法等信息，去找一个合适的 RequestMappingInfo，从而定位到正确的 Controller 方法来执行。
 * 注意：重写hashcode
 */
@SuppressWarnings("all")
public class RequestMappingInfo {

    /**
     * 请求的uri
     */
    private String requestMappingPattern;

    /**
     * 请求方式
     */
    private String method;

    public RequestMappingInfo() {
    }

    public RequestMappingInfo(String requestMappingPattern, String method) {
        this.requestMappingPattern = requestMappingPattern;
        this.method = method;
    }

    public String getRequestMappingPattern() {
        return requestMappingPattern;
    }

    public void setRequestMappingPattern(String requestMappingPattern) {
        this.requestMappingPattern = requestMappingPattern;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RequestMappingInfo that = (RequestMappingInfo) o;
        return Objects.equals(requestMappingPattern, that.requestMappingPattern) && Objects.equals(method, that.method);
    }

    @Override
    public int hashCode() {
        return Objects.hash(requestMappingPattern, method);
    }
}
